const API = require('./base')



export function getMenu(data) {
  return API.get('/wp-json/mp/v2/menu', data);
}

export function getStickyList(args) {
  return API.get('/wp-json/mp/v2/forums?sticky=true', args);
}

export function getTopicList(data) {
  return API.get('/wp-json/mp/v2/forums', data, {
    token: true
  });
}

export function getDetail(id, type) {
  return API.get('/wp-json/mp/v2/' + type + '/' + id, {}, {
    token: true
  });

}

export function getCircleList(data) {
  return API.get('/wp-json/wp/v2/circle?orderby=id&order=asc&per_page=20', data, {
    token: true
  });
}


export function getRelateForum(id, type) {
  return API.get('/wp-json/mp/v2/' + type + '?custom=relate&per_page=3&id=' + id);
}


export function getTopicsTags(data) {
  return API.get('/wp-json/wp/v2/topic', data);
}

export function addForums(type, data) {
  if (type == 'posts') {
    return API.post('/wp-json/mp/v2/posts', data, {
      token: true
    });
  } else {
    return API.post('/wp-json/mp/v2/posts?type=forums', data, {
      token: true
    });
  }
}

export function deletePost(id, type) {
  if (type == "circle") {
    return API.delete('/wp-json/mp/v2/circle/posts?id=' + id, {}, {
      token: true
    });
  } else {
    return API.delete('/wp-json/mp/v2/posts?post_id=' + id, {}, {
      token: true
    });
  }
}

export function deleteComment(id) {
  return API.delete('/wp-json/mp/v2/comments?comment_id=' + id, {}, {
    token: true
  });
}

export function getFollowForums(data) {
  return API.get('/wp-json/mp/v2/forums?custom=follow', data, {
    token: true
  });
}

export function getUserForum(data) {
  return API.get('/wp-json/mp/v2/forums', data);
}

export function creatCircles(data) {
  return API.post('/wp-json/mp/v2/circle/creat', data, {
    token: true
  });
}

export function getAuditList(data) {
  return API.get('/wp-json/mp/v2/circle/audit', data, {
    token: true
  });
}

export function verifyAudits(data) {
  return API.post('/wp-json/mp/v2/circle/audit', data, {
    token: true
  });
}

export function getCircleByID(id) {
  return API.get('/wp-json/wp/v2/circle/' + id, id, {
    token: true
  });
}

export function getVideoLists(data) {
  return API.get('/wp-json/mp/v2/forums?format=video&per_page=10', data);
}

export function getCircleByMines(data) {
  return API.get('/wp-json/mp/v2/circle', data, {
    token: true
  });
}

export function joinCircles(id) {
  return API.post('/wp-json/mp/v2/circle?action=join&id=' + id, {
    token: true
  })
}

export function quitCircles(id) {
  return API.post('/wp-json/mp/v2/circle?action=quit&id=' + id, {
    token: true
  })
}

export function getLocationPosts(lng, lat) {
  return API.get('/wp-json/mp/v2/forums?custom=location&longitude=' + lng + '&latitude=' + lat)
}

export function getsignLists(data) {
  return API.get('/wp-json/mp/v2/sign/posts', data, {
    token: true
  });
}

export function getReview(args) {
  return API.get('/wp-json/mp/v2/review', args, {
    token: true,
  })
}

export function reviewPost(data, type) {
  if (type == "cirlce") {
    return API.post('/wp-json/mp/v2/circle/posts', data, {
      token: true
    });
  } else {
    return API.put('/wp-json/mp/v2/posts', data, {
      token: true
    });
  }
}
export function reviewComment(data) {
  return API.put('/wp-json/mp/v2/comments', data, {
    token: true
  });
}

export function auditCirclePost(data) {
  return API.get('/wp-json/mp/v2/circle/posts', data, {
    token: true
  });
}


export function getCommentsReview(args) {
  return API.get('/wp-json/mp/v2/comments/review', args, {
    token: true,
  })
}

export function getRandTopic(data) {
  return API.get('/wp-json/mp/v2/forums?orderby=rand', data);
}


export function getMemberlist(id, data) {
  return API.get('/wp-json/mp/v2/circle/' + id, data, {
    token: true,
  })
}

/**
 *  扫描二维码登录网站
 * @param  {object} args 参数
 * TOKEN 参数为 true ,需要用户授权使用
 * @return {promise}
 */
export function qrcodeLogin(data) {
  return API.post('/wp-json/mp/v2/user/auth', data, {
    token: true
  });
}

export function creditSubscribe(data) {
  return API.post('/wp-json/mp/v2/credit/subscribe', data, {
    token: true
  })
}